package com.etpjava.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.etpjava.model.Department;
import com.etpjava.service.DepartmentService;
import com.etpjava.service.impl.DepartmentServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

public class DepartmentAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = -7009516180636288803L;
	Log logger=LogFactory.getLog(DepartmentAction.class);
	private Department dp;
	private DepartmentService dps=new DepartmentServiceImpl();
	private List<Department> listdep;
	private int id;
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Department getDp() {
		return dp;
	}

	public void setDp(Department dp) {
		this.dp = dp;
	}
	public List<Department> getListdep() {
		return listdep;
	}

	public void setListdep(List<Department> listdep) {
		this.listdep = listdep;
	}

	public String addDep(){//添加部门
		logger.info("添加部门名============"+dp.getName());
		if(dps.saveDep(dp)){
			return SUCCESS;
		}else{
			return "fail";
		}
	}
	public String delDep(){//删除部门
		logger.info("删除部门id============"+id);
		if(dps.delDep(id)){
			return SUCCESS;
		}else{
			
			return "fail";
		}
	}
	
	public String updDep(){//修改部门
		logger.info("修改部门id============"+id);
		if(dps.updDep(dp)){
			return SUCCESS;
		}else{
			
			return "fail";
		}
	}
	
	public String selectById(){
		dp=dps.selectById(id);
		return SUCCESS;
	}
	
	public String selectByName(){
		listdep=dps.selectByName(dp.getName());
		return SUCCESS;
	}
	
	public String selectByTime(){
		listdep=dps.selectByCreateTime(dp.getBuildTime());
		return SUCCESS;
	}
	
	public String selectAll(){//查找所有部门
		listdep=dps.selectAll();
		logger.info("查找所有部门id=================="+listdep.iterator().next().getId());
		return SUCCESS;
	}
	
}
